
package file.stuff.learn;

/**
 *
 * @author eburdick
 * 
 * Trying out code to manipulate directories
 */
import java.io.File;

/*
 * top class corresponding to the file
 */
public class FileStuffLearn 
{

    /**
     * main program
     * args[0] is the path to start with
     */
    public static void main(String[] args) 
    {
        // first call of the displayIt member function
        displayIt(new File(args[0]));
    }
    /*
     * Member function to print out names of directory entries, called "node".
     * If the entry is itself a directory, the function is called recursively
     * after the entry name is printed.
     */
    public static void displayIt(File node)
    {
        /*
         * output the absolute file name of node
         */
	System.out.println(node.getAbsoluteFile());
 
        /*
         * if node is a directory, then traverse all of its entries, calling
         * this method for each one.
         */
        if(node.isDirectory())
        {
            /*
             * create string array subNote populated with a list 
             * of directory entries.
             */
            String[] subNote = node.list();
            /*
             * Use for-each loop to recursively call this method 
             * for each element in string array subNote.
             * 
             * filename is declared locally as a string, and is the
             * index variable that contains a copy of each element of
             * the array subNote for each iteration.
             */
            for(String filename : subNote)
            {
                /*
                 * call this method, creating a new file object to use
                 * as context for the recursive call.  The current "node" is
                 * the parent and the directory element is the file name.
                 */
                displayIt(new File(node, filename));
            }
	}
    }
}